<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="java.util.Date" %>
<%@ include file="/WEB-INF/views/include.inc.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>飞行计划及风温上传管理系统</title>

    <link rel="stylesheet" type="text/css" href="${contextPath}/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="${contextPath}/css/top.css">
    <link rel="stylesheet" type="text/css" href="${contextPath}/css/foot.css">
    <link rel="stylesheet" type="text/css" href="${contextPath}/css/common.css">
    <link rel="stylesheet" type="text/css" href="${contextPath}/css/message.css">

    <script src="${contextPath}/js/jquery.js"></script>
    <script src="${contextPath}/js/bootstrap.min.js" type="text/javascript"></script>
    <script src="${contextPath}/js/dataformat.js" type="text/javascript"></script>
    <script src="${contextPath}/js/menu_top.js" type="text/javascript"></script>
    <script src="${contextPath}/js/localtime.js" type="text/javascript"></script>
    <script src="${contextPath}/js/My97DatePicker/WdatePicker.js" type="text/javascript"></script>

    <script type="text/javascript">
        var sendStatusArr = [
            {value: '1', text: '已发送', cls: 'btn-warning',statusText:'SEND'},
            {value: '2', text: '未发送', cls: 'btn-warning',statusText:'UNSEND'},
            {value: '3', text: '没有飞行计划', cls: 'btn-danger',statusText:'NOPLAN'},
            {value: '4', text: '数据缺失', cls: 'btn-danger',statusText:'NODATA'}
        ];
        var captainStatusArr = [
            {value: 'AC', text: '机组已确认', cls: 'btn-success',statusText:'AC'},
            {value: 'RJ', text: '机组已拒绝', cls: 'btn-danger',statusText:'RJ'},
            {value: 'AK', text: 'FMC已确认', cls: 'btn-success',statusText:'AK'},
            {value: 'REJ', text: 'FMC拒绝', cls: 'btn-danger',statusText:'REJ'}
        ]
        var masNumArr = [
            {value: 'S', text: '机载设备已收', cls: 'btn-success',statusText:'MAS'},
            {value: 'F', text: '机载设备未收到', cls: 'btn-danger',statusText:'MAS'},
            {value: 'I', text: '上行回复已发送', cls: 'btn-warning',statusText:'MAS'}
        ]
        function getStatusItem(item){
            var status,statusArr;
            debugger
            if(item.captainStatus!='0'){
                status=item.captainStatus;
                statusArr=captainStatusArr;
            }else if(item.masNum && item.masNum!=''){
                status=item.masNum;
                statusArr=masNumArr;
            }else{
                status=item.sendStatus;
                statusArr= sendStatusArr;
            }
            var statusItem;
            for (var i = 0; i < statusArr.length; i++) {
                if(status.endsWith(statusArr[i].value)){
                    statusItem = statusArr[i];
                    break;
                }
            }

            return statusItem||statusArr[0];
        }
        $(function () {
            $(".main-body").load('${contextPath}/monitor/monitor');
            $("#changepwd").click(function () {
                $(".modal").modal('show');
                $(".modal .modal-body").load('${contextPath}/updatePwd');
            })

            $.ajaxSetup({
                complete: function (xhr, status) {
                    if(xhr.responseText.startsWith('{')){
                        var data = JSON.parse(xhr.responseText);
                        if (data.statusCode == '301') {
                            var yes = confirm(data.message);
                            if (yes) {
                                getTopWinow().location.href = '${contextPath}/index';
                            }
                        }
                    }
                }
            });

            var refreshServer = setInterval(function(){
                $.get('${contextPath}/serviceStatus/load',{},function(data){
                    if(data.serviceStatuss){
                        $.each(data.serviceStatuss,function(index,item){
                            if(item.status == '1'){
                                $("#"+item.serviceName).addClass('btn-success')
                            }else{
                                $("#"+item.serviceName).addClass('btn-danger')
                            }
                        })
                    }
                },'json')
            },30000);
        })

        /**
         * 在页面中任何嵌套层次的窗口中获取顶层窗口
         * @return 当前页面的顶层窗口对象
         */
        function getTopWinow(){
            var p = window;
            while(p != p.parent){
                p = p.parent;
            }
            return p;
        }
    </script>
</head>

<body>
<!-- 页头 -->
<div class="main-top"><!-- Split button -->
    <div class="main-top-logo">
        <%--<img src="${contextPath}/images/flightoperator-logo-lightblue.png">--%>
        <img src="${contextPath}/images/flightoperator-logo-pink.png">
    </div>
    <div class="main-top-menu">
        <ul>
            <li id="monitor" class="active" href="${contextPath}/monitor/monitor">实时监控</li>
            <li id="query-flightplan" href="${contextPath}/query/firstlist">飞行计划查询</li>
            <li id="query-windinfo" href="${contextPath}/query/firstlistwid">风温信息查询</li>
        </ul>
    </div>
    <div class="main-top-user">
        <div class="server-status">
            <c:forEach var="item" items="${serviceStatuss}">
                <c:choose>
                    <c:when test="${item.status == '1'}">
                        <button id="${item.serviceName}" class="btn btn-sm btn-success">${item.serviceName}</button>
                    </c:when>
                    <c:when test="${item.status == '2'}">
                        <button id="${item.serviceName}" class="btn btn-sm btn-danger">${item.serviceName}</button>
                    </c:when>
                </c:choose>
            </c:forEach>
        </div>
        <span>当前时间：</span>
        <span id="localtime" class="localtime"></span>
        <span class="user-logo"> <img src="${contextPath}/images/icon/user.png"></span> <span
            class="user">${login_user.username }</span>
        <a href="${contextPath}/logout" class="logout">
            <img src="${contextPath}/images/icon/logout.png">注销
        </a>
    </div>
</div>
<div class="main-top-bottom"></div>

<!-- 内容主体 -->
<div class="main-body">
</div>

<!-- 页脚 -->
<div class="main-footer"></div>

<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close"
                        data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    修改密码
                </h4>
            </div>
            <div class="modal-body">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button id="sendBtn" type="button" class="btn btn-primary">发送</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
</div>
</body>
</html>
